<template>
  <div class="content-wrapper">
    <div class="content-container">
      <el-page-header :content="title" @back="goBack" />

      <el-table
        v-loading="listLoading"
        height="75vh"
        :data="dataList"
        highlight-current-row
        default-expand-all
        :row-key="getId"
      >
        <el-table-column
          label="培训人员"
          prop="userName"
          min-width="100px"
        />

        <el-table-column
          label="所属部门"
          prop="userGroupName"
          width="160px"
        />
        <el-table-column
          label="试卷名称"
          prop="examinationPaperName"
          min-width="200px"
        />
        <el-table-column label="学习总时长" prop="learnDurationString" width="160px" />
        <el-table-column label="学习总次数" prop="score" width="100px" />
        <el-table-column
          label="操作"
          align="center"
          width="150px"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-dropdown
              v-if="scope.row.trainId"
              trigger="click"
              class="filter-item"
            >
              <el-button type="text" class="el-icon-more" />
              <el-dropdown-menu slot="dropdown" class="user-dropdown">
                <el-dropdown-item>
                  <el-popover placement="left" width="400" trigger="hover">
                    <el-table
                      class="my-popover-table"
                      :data="scope.row.trainDocumentRelResponses"
                      :row-key="viewRecordId"
                    >
                      <el-table-column
                        label="文档名称"
                        prop="documentName"
                        min-width="200px"
                      />

                      <el-table-column
                        width="100"
                        property="learnDuration"
                        label="学习时长"
                      />
                      <el-table-column
                        width="100"
                        property="score"
                        label="学习次数"
                      />
                    </el-table>
                    <span slot="reference"> 自学历史 </span>
                  </el-popover>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page-number.sync="listQuery.pageNumber"
        :page-size.sync="listQuery.pageSize"
        @pagination="getDataList"
      />
    </div>
  </div>
</template>

<script>
import { listRecordByTrain } from '@/api/ts/record.js'
import Pagination from '@/components/Pagination'
export default {
  components: { Pagination },
  data() {
    return {
      dataList: [],
      total: 0,
      paperOptions: [],
      userGroupOptions: [],
      listQuery: {
        pageIndex: 0,
        pageNumber: 1,
        withLearnRecords: true,
        trainId: ''
      },
      listLoading: false,
      recordViewDialog: false, // 查看对话框
      propsData: null,
      title: ''
    }
  },
  watch: {},
  mounted() {
    this.listQuery.trainId = this.$route.query.trainId
    console.log(this.$route.query, '324444')
    this.title = this.$route.query.trainName
    this.getDataList()
  },
  methods: {
    getDataList() {
      listRecordByTrain(this.listQuery).then((res) => {
        this.dataList = res.data
      })
    },
    viewRecord(row, column, event) {
      this.$emit('viewRecord', row.examinationRecordId)
    },
    handleFilter() {},
    // c重新考核
    reloadExamine(row) {
      console.log(row)
    },
    // 考试记录
    testHistory(row) {
      console.log(row)
    },
    getId(row) {
      return row.userId
    },
    viewRecordId(row) {},
    goBack() {
      this.$router.go(-1)
    }
  }
}
</script>
<style scope>
.view_record .el-dialog .el-dialog__header {
  padding: 0px !important;
}
.view_record .el-dialog .el-dialog__body {
  padding: 30px 0px !important;
}
.my-popover-table {
  height: unset;
}
</style>
